<?php
    class Silabus_con extends CI_Controller{
        function __construct() {
            parent::__construct();
            //cek session
            if(!$this->session->userdata('islogin')){
                redirect(base_url().'admin');
            }
        }
        function index(){
            //Di sini akan menampilkan halaman default
            //Rencananya akan ditampilkan tabel dari silabus yang udah ada
            $this->tampil_silabus();
        }
        function tampil_silabus(){
            //akan menmapilkan silabus yang sudah dibuat dalam bentuk tabel
            $query = $this->db->get('silabus');
            if($query->num_rows()>0){
                $this->load->library('table');
                $this->table->set_template(array('table_open' => '<table border="1" cellpadding="4" cellspacing="3">'));
                $this->table->set_heading('NO', 'NAMA SILABUS','AKSI');
                $i=1;
                foreach ($query->result() as $entry) {
                    $this->table->add_row(
                            $i, $entry->NAMA_SILABUS,
                            anchor(base_url() . 'admin/silabus_con/hapus_silabus/' . $entry->ID_SILABUS, 'Delete') .
                            ' | ' .
                            anchor(base_url() . 'admin/chapter_con/disp_form/' . $entry->ID_SILABUS, 'Isi Silabus'));
                    $i++;
                }
                $display['content']=$this->table->generate();
            }else{
                $display['content']="Belum ada silabus yang dibuat";
            }
            $data['title']="Silabus Pelatihan";
            $this->load->view('admin/admin_header_view', $data);
            $this->load->view('admin/silabus_disp_view', $display);
            $this->load->view('footer_view');
        }
        function tambah_silabus(){
            //memasukkan silabus baru ke dalam database
            $nama = $this->input->post('NAMA_SILABUS');
            if($nama!=''){
                $this->db->insert('silabus',$_POST);
            }
            redirect(base_url() . 'admin/silabus_con');
        }
        function hapus_silabus($id){
            //menghapus silabus dari database
            $this->db->delete('silabus',array('ID_SILABUS'=>$id));
            $this->db->delete('chapter',array('ID_SILABUS'=>$id));
            redirect(base_url() . 'admin/silabus_con');
        }
    }
?>
